package com.hyjx.framework.component.excel.template;

import com.hyjx.framework.orm.dao.IBaseDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * excel配置模板服务实现类
 */
@Service(value = "excelTemplateService")
@Transactional
public class ExcelTemplateServiceImpl implements ExcelTemplateService {

    @Resource
    private IBaseDao dao;

    @Override
    public String query(ExcelTemplate et) {
        return this.dao.getPageJsonStr(et.getModuleName() + ".select", et.getModuleName() + ".count", et);
    }

    @Override
    public void insert(ExcelTemplate et) {
        this.dao.addObject(et.getModuleName() + ".insert", et);
    }

    @Override
    public void delete(ExcelTemplate et) {
        this.dao.deleteObject(et.getModuleName() + ".delete", et);
    }

    @Override
    public void update(ExcelTemplate et) {
        this.dao.updateObject(et.getModuleName() + ".update", et);
    }

    @Override
    public List<ExcelTemplate> queryList(ExcelTemplate et) {
        return (List<ExcelTemplate>) this.dao.queryObjectList(et.getModuleName() + ".select", et);
    }

    @Override
    public boolean isEnNameExists(ExcelTemplate et) {
        String count = this.dao.queryObjectList(et.getModuleName() + ".count", et).get(0).toString();
        if (!"0".equals(count))
            return true;
        return false;
    }

    @Override
    public boolean isEnNameExistsEdit(ExcelTemplate et) {
        ExcelTemplate etNew = new ExcelTemplate();
        etNew.setModule_en_name(et.getModule_en_name());
        etNew.setPub_excel_template_id(null);
        List etList = this.dao.queryObjectList(et.getModuleName() + ".select", etNew);
        if (etList != null && etList.size() >= 1) {
            ExcelTemplate et1 = (ExcelTemplate) etList.get(0);
            if (et1.getPub_excel_template_id().equals(et.getPub_excel_template_id())) {
                return false;
            } else {
                return true;
            }
        } else if (etList != null && etList.size() == 0) {
            return false;
        }
        return true;
    }
}